<?php

use think\migration\Migrator;
use think\migration\db\Column;

class Cart extends Migrator
{
    /**
     * Change Method.
     *
     * Write your reversible migrations using this method.
     *
     * More information on writing migrations is available here:
     * http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
     *
     * The following commands can be used in this method and Phinx will
     * automatically reverse them when rolling back:
     *
     *    createTable
     *    renameTable
     *    addColumn
     *    renameColumn
     *    addIndex
     *    addForeignKey
     *
     * Remember to call "create()" or "update()" and NOT "save()" when working
     * with the Table class.
     */
    public function change()
    {
        $table = $this->table('cart', ['engine' => 'InnoDB', 'comment' => '购物车', 'signed' => false]);
        $table->addColumn('company_id', 'integer', ['limit' => 10, 'default' => 0, 'comment' => '公司id', 'signed' => false])
              ->addColumn('store_id', 'integer', ['limit' => 10, 'default' => 0, 'comment' => '门店id', 'signed' => false])
              ->addColumn('salesman_id', 'integer', ['limit' => 10, 'default' => 0, 'comment' => '业务员id', 'signed' => false])
              ->addColumn('dealer_goods_id', 'integer', ['limit' => 10, 'default' => 0, 'comment' => '经销商商品id', 'signed' => false])
              ->addColumn('dealer_goods_spec_id', 'integer', ['limit' => 10, 'default' => 0, 'comment' => '经销商商品规格id', 'signed' => false])
              ->addColumn('company_warehouse_id', 'integer', ['limit' => 10, 'default' => 0, 'comment' => '仓库id', 'signed' => false])
              ->addColumn('goods_type', 'integer', ['limit' => 1, 'default' => 0, 'comment' => '订单内商品类型：1销售，2赠品，3退货，4换货', 'signed' => false])
              ->addColumn('sale_price', 'decimal', ['default' => 0.00, 'comment' => '原售价', 'signed' => false])
              ->addColumn('true_price', 'decimal', ['default' => 0.00, 'comment' => '下单价格', 'signed' => false])
              ->addColumn('num', 'integer', ['default' => 0, 'comment' => '数量', 'signed' => false])
              ->addColumn('total_price', 'decimal', ['default' => 0.00, 'comment' => '总价', 'signed' => false])
              ->addColumn('remark', 'string', ['limit' => 255, 'default' => '', 'comment' => '备注', 'collation' => 'utf8mb4_general_ci'])
              ->addIndex('store_id', ['name' => 'idx_store_id'])
              ->addIndex('salesman_id', ['name' => 'idx_salesman_id'])
              ->addIndex('dealer_goods_id', ['name' => 'idx_dealer_goods_id'])
              ->addIndex('dealer_goods_spec_id', ['name' => 'idx_dealer_goods_spec_id'])
              ->addIndex('goods_type', ['name' => 'idx_goods_type'])
              ->create();
    }
}
